<template>
  <div>
    <Hearder />
    <el-card>
      <el-alert
        title="提示:只能看见三级分支"
        :closable="false"
        show-icon
        type="warning"
      >
      </el-alert>
      <el-row class="xx">
        <el-col>
          <span>选择商品分类:</span>
          <el-cascader
            v-model="slectList"
            :options="cascadeList"
            :props="cascade"
            @change="handleChange"
          >
          </el-cascader>
        </el-col>
      </el-row>

      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="动态参数" name="only">
          <el-button type="danger" :disabled="istabs">动态 </el-button>

          <el-table :data="cascadeList" border stripe>
            <el-table-column prop="cat_name" label="家电类"> </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="静态属性" name="many">
          <el-button type="danger" :disabled="istabs">静态</el-button>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dynamicOnly: [],
      static: [],
      activeName: "only",
      slectList: [],
      cascade: {
        value: "cat_id",
        label: "cat_name",
        children: "children",
      },
      cascadeList: [],
      getInfo: {
        type: 3,
        pagenum: 1,
        pagesize: 5,
      },
    };
  },
  methods: {
    handleClick() {
      this.getTabList();
    },
    async handleChange() {
      this.getTabList();
    },
    async getTabList() {
      const { data: res } = await this.$http
        .get(`categories/${this.tabsId}/attributes`, {
          params: { sel: this.activeName },
        })
        .catch((err) => err);
      console.log(res);
      if (this.activeName === "only") {
        this.dynamicOnly = res.data;
      } else {
        this.static = res.data;
      }
    },
    async getcascadeList() {
      const { data: res } = await this.$http
        .get("categories", { params: this.getInfo })
        .catch((err) => err);
      this.cascadeList = res.data.result;
      console.log(111111, res.data, this.slectList);
    },
  },
  computed: {
    istabs() {
      if (this.slectList.length !== 3) {
        return true;
      } else {
        return false;
      }
    },
    tabsId() {
      if (this.slectList.length === 3) {
        return this.slectList[2];
      } else {
        return null;
      }
    },
  },
  mounted() {
    this.getcascadeList();
  },
};
</script>

<style>
.xx {
  margin: 10px;
}
</style>
